<!DOCTYPE html>
<html>
<head>

<link rel="stylesheet" type="text/css" href="../CssFrame/bootstrap-theme.css">
<link rel="stylesheet" type="text/css" href="../CssFrame/bootstrap.css">

<script src="../Jquery/Jquery-3.3.1.js" type="text/javascript"></script>

<meta charset="UTF-8">

<style type="text/css">
</style>

<title>修改宿管员资料</title>
</head>
<body>
	<div style="text-align: center;" class="container">
		<div class="row">
			<h3>修改个人资料</h3>
		</div>
		<div class="panel-body">
			<form class="form-horizontal" role="form" id="own_form">
				<div class="form-group">
					<label for="inputPassword3" class="col-sm-2 control-label">名字</label>
					<div class="col-sm-10">
						<input type="text" class="form-control" placeholder="" maxlength="18" name="hpname" id="input_hpname">
					</div>
				</div>
				<!--  -->
				<div class="form-group">
					<label for="inputPassword3" class="col-sm-2 control-label">电话</label>
					<div class="col-sm-10">
						<input type="text" class="form-control" placeholder="" maxlength="18" name="phone" id="input_phone">
					</div>
				</div>
				<!--  -->
				<div class="form-group">
					<label for="inputPassword3" class="col-sm-2 control-label">身份证号</label>
					<div class="col-sm-10">
						<input type="text" class="form-control" maxlength="18" placeholder="" name="idCard" id="input_idCard">
					</div>
				</div>
				<!--  -->
				<div class="form-group" style="text-align: center;">
					<input type="button" class="btn btn-default" value="OK" id="btn_confirm" style="margin-right: 25px;"> <input
						type="reset" class="btn btn-default" value="重置" style="margin-left: 25px;">
				</div>
		</div>
		<div>
			<a href="ShowOwnProfile.html">返回资料展示页</a>
		</div>
	</div>
</body>
<!--  -->
<script type="text/javascript">
	$(document).ready(function() {
		exhibitPrevProfile();
	});

	/**////////////////////////// */
	function exhibitPrevProfile() {
		var url = '/dormitory/HouseParents/exhibitProfile';

		$.ajax({
			"url" : url,
			"dataType" : "json",
			"type" : 'GET',
			"success" : function(r) {
				/*  */
				if (r.state === 200) {
					$('#input_hpname').prop('placeholder', r.data.hpname);
					$('#input_phone').prop('placeholder', r.data.phone);
					$('#input_idCard').prop('placeholder', r.data.idCard);

				} else {
					alert(r.message);
				}
				/*  */
			}
		/*  */
		});
	}

	/*\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ */
	$('#btn_confirm').on('click', function() {
		var hpname = $('#input_hpname').val();
		var phone = $('#input_phone').val();
		var idCard = $('#input_idCard').val();

		if (hpname == '' || hpname == null || phone == '' || phone == null || idCard == '' || idCard == null) {
			alert('There are still some uncompleted');
			return false;
		}

		/**/
		if (hpname.length < 3) {
			alert("用户名不得少于3位");
			return;
		}
		/**/

		/*身份证号正则表达式,18位*/
		var expression = /^[1-9]\d{5}(18|19|20|(3\d))\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/;
		var exp = new RegExp(expression);
		if (exp.test(idCard) == false) {
			alert('身份证号码无效')
			return;
		}

		/* 至少9位的数字: ^\d{9,}$ */
		var expression01 = /^\d{9,}$/;
		var exp01 = new RegExp(expression01);
		if (exp01.test(phone) == false) {
			alert('手机号码格式有误')
			return;
		}

		var data = $('#own_form').serialize();
		var url = '/dormitory/HouseParents/revampPartialProfileHandler';

		$.ajax({
			url : url,
			type : 'POST',
			data : data,
			dataType : 'json',
			success : function(r) {
				if (r.state === 200) {
					alert('修改资料成功');
					location.href = 'ShowOwnProfile.html';
				} else {
					alert(r.message);
				}
			}
		})

	})
</script>
</html>